<?php

namespace app\admin\model;

use think\Model;

/**
 * Feedback
 * @controllerUrl 'feedback'
 */
class Feedback extends Model
{
    // 表名
    protected $name = 'feedback';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    protected $type = [
        'delete_time' => 'timestamp:Y-m-d H:i:s',
    ];


    public function getUserIdAttr($value, $row)
    {
        return !$value ? '' : $value;
    }

    public function getImagesAttr($value, $row)
    {
        if ($value == '') {
            return [];
        }
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setImagesAttr($value, $row)
    {
        if ($value && is_array($value)) {
            return implode(',', $value);
        }
        return $value ? $value : '';
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
}